package com.shhm.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.business.mapper.ProductTypeMapper;
import com.shhm.business.service.ProductTypeService;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.common.ProductTypeEntity;
import com.shhm.common.utils.MybatisPlusUtil;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/10 下午12:09
 */
@Service
public class ProductTypeServiceImpl implements ProductTypeService {
    @Resource
    private ProductTypeMapper productTypeMapper;
    
    @Override
    public AjaxResultPlus productTypeList(Integer pageNum, Integer pageSize, Integer isPage) {
        if (isPage==0) {
            List<ProductTypeEntity> list = productTypeMapper.selectList(null);
            return AjaxResultPlus.success(list,false);
        }
        PageDTO<ProductTypeEntity> userPage = new PageDTO<>(pageNum, pageSize);
        PageDTO<ProductTypeEntity> list=productTypeMapper.selectPage(userPage, null);
        return AjaxResultPlus.custom(200, false)
                .put("data",list)
                .put("operateStr","*");
    }

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, ProductTypeEntity entity) {
        PageDTO<ProductTypeEntity> userPage = new PageDTO<>(pageNum, pageSize);
        QueryWrapper<ProductTypeEntity> qw = MybatisPlusUtil.buildSearchQueryWrapper(entity);
        PageDTO<ProductTypeEntity> list = productTypeMapper.selectPage(userPage, qw);
        return AjaxResultPlus.success(list,false);
    }

    @Override
    public AjaxResultPlus add(ProductTypeEntity entity) {
        entity.createLocalDateTime();
        return ResponseUtil.sqlExeIsSuccess(productTypeMapper.insert(entity));
    }

    @Override
    public AjaxResultPlus update(ProductTypeEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(productTypeMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(productTypeMapper.deleteByIds(list));
    }

    @Override
    public AjaxResultPlus prodTypeList() {
        LambdaQueryWrapper<ProductTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<ProductTypeEntity>().eq(ProductTypeEntity::getStatus, 0);
        return AjaxResultPlus.success(productTypeMapper.selectList(lambdaQueryWrapper),false);
    }
}
